package design_pattern.proxy_pattern.dynamic_proxy;

import design_pattern.proxy_pattern.static_proxy.LandLord;
import design_pattern.proxy_pattern.static_proxy.Landlady;

/**
 * @author Cheng Jun
 * Description: 测试jdk的动态代理
 * 视频学习地址见 ../note.md:2
 * @version 1.0
 * @date 2022/7/20 21:01
 * @see
 */
public class JDK_DProxy_Test {

    public static void main(String[] args) {
        // 是否将JDK动态代理生成的Class文件保存到硬盘
        System.setProperty("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        Landlady wang = new Landlady("王阿姨");
        // 只能转换成接口 去接收，因为jdk的动态代理类 实现了被代理对象的所有接口，且必须继承Proxy
        // dynamicProxy 相等于房屋中介
        LandLord dynamicProxy = (LandLord) new JDK_DProxy().getProxy(wang);
        dynamicProxy.rentHouse(100);
        System.out.println(dynamicProxy.getClass());

        // Student xiaoming = new Student("xiaoming");
        // Student proxy = (Student) new JDK_DProxy().getProxy(xiaoming);
        // proxy.sayName();
    }
}
